/***
 * CaRComp Translator
 * 
 * Copyright (C) 2011 Taylor L. Riche
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ***/

package translator.objects;

import java.io.PrintStream;

public abstract class Entity {

	private String ident;
	private String name;

	public Entity() {}
	
	/**
	 * @param ident
	 */
	public Entity(String ident) {
		this.ident = ident.replace("\"", "");
	}
	
	public Entity(String ident, String name) {
		this.ident = ident.replace("\"", "");
		this.name = name.replace("\"", "");
	}
		

	public String getIdent() {
		return this.ident;
	}
	
	public String getName() {
		return this.name;
	}
	
	public String getPackage() {
		return convertCamelCase(this.name);
	}
	
	public String getNID() {
		return this.name + "_" + this.ident;
	}

	public abstract void generateCode(PrintStream fo) ;

	public static String convertCamelCase(String s) {
		   return s.replaceAll(
		      String.format("%s|%s|%s",
		         "(?<=[A-Z])(?=[A-Z][a-z])",
		         "(?<=[^A-Z])(?=[A-Z])",
		         "(?<=[A-Za-z])(?=[^A-Za-z])"
		      ),
		      " "
		   ).replace(' ', '_').toLowerCase();
		}
	
}